package com.yc.jpyy.mobile.service.imp;

import java.io.File;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import Decoder.BASE64Decoder;

import com.alibaba.fastjson.JSONObject;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.config.Config;
import com.yc.jpyy.base.service.BaseService;
import com.yc.jpyy.common.Common;
import com.yc.jpyy.mobile.dao.BizDao;
import com.yc.jpyy.mobile.service.BizService;
import com.yc.jpyy.mobile.service.CommonService;

@Service
public class BizServiceImpl extends CommonService implements BizService {

	@Autowired
	private BizDao bizDao;

	@Override
	public RestResponse getReleaseCourse(
			Map<String, Object> paramsMap,RestResponse response) throws DataAccessException {
		checkPageParamsMap(paramsMap);
		List<Map<String, Object>> releaseCourseMaps =  bizDao.getReleaseCourse(paramsMap);
		//过滤后的值
		List<Map<String, Object>> releaseCourseMap = new ArrayList<Map<String, Object>>();
		//截取后的值
		List<Map<String, Object>> subMap = new ArrayList<Map<String, Object>>();
		//过滤分校指定班型
		if (null != releaseCourseMaps && releaseCourseMaps.size() > 0) {
			for(Map<String, Object> map:releaseCourseMaps){
				if(Optional.ofNullable(map.get("AppRange")).orElse("").toString().equals("3")){
					if(Arrays.asList(Optional.ofNullable(map.get("ClassIDS")).orElse(0).toString().split(";")).contains(paramsMap.get("classInfoId").toString())){
						releaseCourseMap.add(map);
					}
				}else{
					releaseCourseMap.add(map);
				}
		    }
			if(null != releaseCourseMap && releaseCourseMap.size() > 0){
				int beginNum = Integer.valueOf(paramsMap.get("beginNum").toString());
				int endNum = Integer.valueOf(paramsMap.get("endNum").toString());
				if(releaseCourseMap.size() >= beginNum && releaseCourseMap.size() <= endNum){
					subMap = releaseCourseMap.subList(beginNum-1,releaseCourseMap.size());
					response.setErrorcode(0);
					response.setData(subMap);
				}else if(releaseCourseMap.size() > endNum){
					subMap = releaseCourseMap.subList(beginNum-1,endNum);
					response.setErrorcode(0);
					response.setData(subMap);
				}else{
					response.setErrorcode(1);
					response.setMessage("暂无更多课程！");
				}
			}else{
				response.setErrorcode(1);
				response.setMessage("暂无更多课程！");	
			}
		} else {
			response.setErrorcode(1);
			response.setMessage("暂无更多课程！");
		}
		return response;
	}

	@Override
	public Map<String, Object> getStudentInfo(String userId)
			throws DataAccessException {

		return bizDao.getStudentInfo(userId);
	}

	@Override
	public List<Map<String, Object>> SelectDriverSchools(String RegionNo)
			throws DataAccessException {

		return bizDao.SelectDriverSchools(RegionNo);
	}


	@Override
	public int updateUserImage(String userImage, String userId)
			throws DataAccessException {
		return bizDao.updateUserImage(userImage, userId);
	}

	@Override
	public List<Map<String, Object>> checkRemind(int minute)
			throws DataAccessException {

		return bizDao.checkRemind(minute);
	}

	@Override
	public List<Map<String, Object>> checkSysAnn(int minute)
			throws DataAccessException {

		return bizDao.checkSysAnn(minute);
	}

	@Override
	public List<Map<String, Object>> getUpdateCourseNo(int minute)
			throws DataAccessException {

		return bizDao.getUpdateCourseNo(minute);
	}


	@Override
	public RestResponse getSpecialTypeQuestion(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		List<Map<String,Object>> map = bizDao.getSpecialTypeQuestion(paramsMap);
		if (map != null && map.size() > 0) {
			for (Map<String, Object> maps : map) {
				maps.put("questionitems",bizDao.getQuestionItemInfo(maps.get("QuestionId").toString()));
				maps.put("sign","");
			}
			response.setData(map);
		} else {
			response.setErrorcode(1);
			response.setMessage("该练习类型下无题目信息...");
		}
		return response;
	}

	@Override
	public RestResponse addQuestionInfo(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		// 查询记录表是否存在该题的记录
		String isError = (String) paramsMap.get("isError");
		int count = bizDao.selectAnswerQuestionId(paramsMap);
		int i = 0;
		if (count <= 0) {
			// 添加答题记录
			i = bizDao.addAnswerQuestion(paramsMap);
		} else {
			// 更改答题表中的答题记录数
			i = bizDao.updateAnswerQuestion(paramsMap);
		}
		if (i > 0) {
			if (isError != null && !isError.isEmpty() && isError.equals("1")) {
				// 更改答题表中的错题记录数
				int j = bizDao.updateAnswerQuestionError(paramsMap);
				if (j > 0) {
					// 查询错题表中是否存在该记录
					int counts = bizDao.selectWrongQuestion(paramsMap);
					if (counts <= 0) {
						// 添加错题记录
						int k = bizDao.addWrongQuestion(paramsMap);
						if (k <= 0) {
							response.setErrorcode(1);
							response.setMessage("错题添加出错...");
						}
					}
				}
			}
		} else {
			response.setErrorcode(1);
			response.setMessage("答题记录添加出错...");
		}
		return response;
	}

	@Override
	public RestResponse addQuestionCollect(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		String isCollect = (String) paramsMap.get("isCollect");
		// 查询收藏表
		int i = bizDao.selectQuestionCollect(paramsMap);
		if (i <= 0) {
			if (isCollect != null && !isCollect.isEmpty()
					&& isCollect.equals("1")) {
				// 添加收藏表
				int j = bizDao.addQuestionCollect(paramsMap);
				if (j <= 0) {
					response.setErrorcode(1);
					response.setMessage("收藏试题出错...");
				}
			}
		} else {
			if (isCollect != null && !isCollect.isEmpty()
					&& isCollect.equals("0")) {
				// 取消收藏
				int k = bizDao.deleteQuestionCollect(paramsMap);
				if (k <= 0) {
					response.setErrorcode(1);
					response.setMessage("取消收藏试题出错...");
				}
			}
		}
		return response;
	}

	@Override
	public RestResponse addExamRecord(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		int k = bizDao.addExamRecord(paramsMap);
		if (k <= 0) {
			response.setErrorcode(1);
			response.setMessage("添加模考记录出错出错...");
		}
		return response;
	}

	@Override
	public RestResponse getCollectionQuestions(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		List<Map<String,Object>> map = bizDao.getCollectionQuestions(paramsMap);
		if (map != null && map.size() > 0) {
			for (Map<String, Object> maps : map) {
				maps.put("questionitems",bizDao.getQuestionItemInfo(maps.get("QuestionId").toString()));
				maps.put("sign","");
			}
			response.setData(map);
		} else {
			response.setErrorcode(1);
			response.setMessage("该练习类型下无题目信息...");
		}
		return response;
	}

	@Override
	public RestResponse getWrongQuestions(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		List<Map<String,Object>> map = bizDao.getWrongQuestions(paramsMap);
		if (map != null && map.size() > 0) {
			for (Map<String, Object> maps : map) {
				maps.put("questionitems",bizDao.getQuestionItemInfo(maps.get("QuestionId").toString()));
				maps.put("sign","");
			}
			response.setData(map);
		} else {
			response.setErrorcode(1);
			response.setMessage("该练习类型下无题目信息...");
		}
		return response;
	}
	
	@Override
	public RestResponse deleteWrongQuestions(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		int i = bizDao.deleteWrongQuestions(paramsMap);
		if (i <= 0){
			response.setErrorcode(1);
			response.setMessage("删除错题记录失败...");
		}
		return response;
	}
	
	
	@Override
	public RestResponse getSimulateQuestions(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		List<Map<String,Object>> map = bizDao.getSimulateQuestions(paramsMap);
		//根据科目获取单选题、多选题、以及判断题的对应分数
		Map<String,Object> scoreMap = bizDao.getScores(paramsMap);
		//模拟通过存储过程取出的试题字段与其他类型取出来的不一致，经过转换一致重新放在一个新的结果集中
		List<Map<String,Object>> resultmap = new ArrayList<Map<String,Object>>();
		if (map != null && map.size() > 0) {
			int i = 0;
			for (Map<String, Object> maps : map) {
				i++;
				Map<String,Object> quemap = new HashMap<>();
				quemap.put("QuestionId",maps.get("Id"));
				quemap.put("ImagePath",Optional.ofNullable(maps.get("FilePath")).orElse(""));
				quemap.put("imgUrl",paramsMap.get("imgUrl"));
				quemap.put("QuesTitle",maps.get("QuesTitle"));
				quemap.put("QuesType",maps.get("QuesType"));
				quemap.put("rownumber",i);
				quemap.put("questionitems",bizDao.getQuestionItemInfo(quemap.get("QuestionId").toString()));
				quemap.put("counts",map.size());
				quemap.put("sign","");
				String quesType = maps.get("QuesType").toString();
				if(quesType.equals("1")){//判断题
					quemap.put("score", scoreMap.get("JudgmentFraction"));
				}else if(quesType.equals("2")){//单选题
					quemap.put("score", scoreMap.get("MCFraction"));
				}else if(quesType.equals("3")){//多选题
					quemap.put("score", scoreMap.get("MCQFraction"));
				}
				resultmap.add(quemap);
			}
			response.setData(resultmap);
		} else {
			response.setErrorcode(1);
			response.setMessage("该练习类型下无题目信息...");
		}
		return response;
	}
	
	@Override
	public RestResponse getDifficultQuestions(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		List<Map<String,Object>> map = bizDao.getDifficultQuestions(paramsMap);
		//根据科目获取单选题、多选题、以及判断题的对应分数
		Map<String,Object> scoreMap = bizDao.getScores(paramsMap);
		//模拟通过存储过程取出的试题字段与其他类型取出来的不一致，经过转换一致重新放在一个新的结果集中
		List<Map<String,Object>> resultmap = new ArrayList<Map<String,Object>>();
		if (map != null && map.size() > 0) {
			int i = 0;
			for (Map<String, Object> maps : map) {
				i++;
				Map<String,Object> quemap = new HashMap<>();
				quemap.put("QuestionId",maps.get("Id"));
				quemap.put("ImagePath",Optional.ofNullable(maps.get("FilePath")).orElse(""));
				quemap.put("imgUrl",paramsMap.get("imgUrl"));
				quemap.put("QuesTitle",maps.get("QuesTitle"));
				quemap.put("QuesType",maps.get("QuesType"));
				quemap.put("rownumber",i);
				quemap.put("questionitems",bizDao.getQuestionItemInfo(quemap.get("QuestionId").toString()));
				quemap.put("counts",map.size());
				quemap.put("sign","");
				quemap.put("percent",maps.get("APercent"));
				quemap.put("errorCount",maps.get("ErrorCount"));
				//查询用户是否有收藏记录
				quemap.put("isCollect",bizDao.getCollectRecord(maps.get("Id").toString(),paramsMap.get("userId").toString())
						               > 0 ? 1 : 0);
				String quesType = maps.get("QuesType").toString();
				if(quesType.equals("1")){//判断题
					quemap.put("score", scoreMap.get("JudgmentFraction"));
				}else if(quesType.equals("2")){//单选题
					quemap.put("score", scoreMap.get("MCFraction"));
				}else if(quesType.equals("3")){//多选题
					quemap.put("score", scoreMap.get("MCQFraction"));
				}
				resultmap.add(quemap);
			}
			response.setData(resultmap);
		} else {
			response.setErrorcode(1);
			response.setMessage("该练习类型下无题目信息...");
		}
		return response;
	}


	@Override
	public RestResponse getSimulateInfo(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		List<Map<String,Object>> map = bizDao.getSimulateInfo(paramsMap);
		if (map != null && map.size() > 0) {
			map.get(0).put("maxTime", Float.parseFloat(Config.getStudyMaxTime())*60);
			response.setData(map.get(0));
		} else {
			response.setErrorcode(1);
			response.setMessage("获取模考信息失败...");
		}
		return response;
	}

	// 驾校信息查询
	@Override
	public RestResponse getDriveSchoolInfo(Map<String, Object> paramMap,
			RestResponse response) throws DataAccessException {
		checkPageParamsMap(paramMap);
		// 获取数据集合
		List<Map<String, Object>> map = bizDao.getDriveSchoolInfo(paramMap);
		if (map != null && map.size() > 0) {
			response.setData(map);
		} else {
			response.setErrorcode(1);
			response.setMessage("暂无更多驾校信息...");
		}
		return response;
	}

	// 驾校信息查询--参数驾校名称
	@Override
	public List<Map<String, Object>> getDrivesInfo(Map<String, Object> paramsMap)
			throws DataAccessException {

		return bizDao.getDrivesInfo(paramsMap);
	}

	// 根据题目ID获取选项
	@Override
	public List<Map<String,Object>> getQuestionItemInfo(String questionid)
			throws DataAccessException {

		return bizDao.getQuestionItemInfo(questionid);
	}

	// 根据驾校ID获取教练下拉
	@Override
	public List<Map<String, Object>> getTeacherListBySchoolID(
			Map<String, Object> paramsMap) throws DataAccessException {
		return bizDao.getTeacherListBySchoolID(paramsMap);
	}

	// 根据区县编号教练列表
	@SuppressWarnings("finally")
	@Override
	public RestResponse getTeacherListByRegion(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		// 处理页数页码
		checkPageParamsMap(paramsMap);
		try {
			// 获取数据集合
			List<Map<String, Object>> map = bizDao
					.getTeacherListByRegion(paramsMap);
			if (map != null && map.size() > 0) {
				response.setData(map);
			} else {
				response.setErrorcode(1);
				response.setMessage("暂无更多教练信息...");
			}
		} catch (Exception e) {
			System.out.println("getTeacherListByRegion:" + e.toString());
			response.setReturnMsg(1, "获取教练信息失败！");
		} finally {
			return response;
		}
	}

	@Override
	public Map<String, Object> getTeacherDetailById(
			Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getTeacherDetailById(paramsMap);
	}

	// 登录
	@Override
	public RestResponse LoginSystemInfo(
			Map<String, Object> paramsMap,RestResponse response) throws DataAccessException {
		//查询用户是否存在
		int count = bizDao.queryUser(paramsMap);
		if(count <= 0){
			response.setErrorcode(1);
			response.setMessage("该用户不存在...");
		}else{
			//登录
			List<Map<String, Object>> stumap = bizDao.LoginSystemInfo(paramsMap);
		    if(stumap != null && stumap.size() >0){
		    	response.setErrorcode(0);
		    	response.setData(stumap);
		    }else{
		    	response.setErrorcode(1);
				response.setMessage("密码填写错误...");
		    }
		}
		return response;
	}

	@Override
	public RestResponse getSecondConfigInfo(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		List<Map<String, Object>> map = bizDao.getSecondConfigInfo(paramsMap);
		if (map != null && map.size() > 0) {
			// 设置Json集合
			response.setData(map);
		} else {
			response.setErrorcode(1);
			response.setMessage("未找到分类信息...");
		}
		return response;
	}

	@Override
	public RestResponse getSpecialSecondConfig(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		List<Map<String,Object>> quesType = bizDao.getSpecialSecondConfig(paramsMap);
		Map<String,Object> resultMap = new HashMap<>();
		resultMap.put("quesType", quesType);
		Map<String,Object> contentQuesCounts = bizDao.selectContentQuesCounts(paramsMap);
		Map<String,Object> typeQuesCounts = bizDao.selectTypeQuesCounts(paramsMap);
		//Map<String,Object> knowQuesCounts = bizDao.selectKnowQuesCounts(paramsMap);
		resultMap.put("contentQuesCounts", contentQuesCounts);
		resultMap.put("typeQuesCounts", typeQuesCounts);
		//resultMap.put("knowQuesCounts", knowQuesCounts);
		if (resultMap != null && resultMap.size() > 0) {
			response.setData(resultMap);
		} else {
			response.setErrorcode(1);
			response.setMessage("未找到分类信息或试题数量...");
		}
		return response;
	}

	// 获取系统公告信息
	@Override
	public RestResponse getNews(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		checkParamsMapForPage(paramsMap);
		List<Map<String, Object>> listData = bizDao.getNews(paramsMap);
		if (null != listData && listData.size() > 0) {
			// 设置数据集合
			response.setData(listData);
		} else {
			response.setErrorcode(1);
			response.setMessage("无驾校通知信息！");
		}
		return response;
	}

	@Override
	public List<Map<String, Object>> getPreRegistrationByTel(String studentTel)
			throws DataAccessException {

		return bizDao.getPreRegistrationByTel(studentTel);
	}

	@Override
	public int addFeedBack(Map<String, Object> paramsMap)
			throws DataAccessException {

		return bizDao.addFeedBack(paramsMap);
	}

	@Override
	public Map<String, Object> getLearnTimeByStuId(String studentId,
			String imgUrl) throws DataAccessException {

		return bizDao.getLearnTimeByStuId(studentId, imgUrl);
	}

	@Override
	public Map<String, Object> getAppointmentLearnTimeByStuId(String studentId)
			throws DataAccessException {
		return bizDao.getAppointmentLearnTimeByStuId(studentId);
	}

	@Override
	public List<Map<String, Object>> getClassTypeById(
			Map<String, Object> paramsMap) throws DataAccessException {
		return bizDao.getClassTypeById(paramsMap);
	}

	@Override
	public String getShopCount(String studentId) throws DataAccessException {
		return bizDao.getShopCount(studentId);
	}

	@Override
	public List<Map<String, Object>> getStudyRecordDetailByStuIdAndSubjectID(
			String studentId) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getStudyRecordDetailByStuIdAndSubjectID(studentId);
	}

	@Override
	public Map<String, Object> getPersonalInformationByTel(
			Map<String, Object> parm) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getPersonalInformationByTel(parm);
	}

	@Override
	public Map<String, Object> getMyInformationById(Map<String, Object> parm)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getMyInformationById(parm);
	}

	@Override
	public int updateDriveSchoolConsultNum(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.updateDriveSchoolConsultNum(paramsMap);
	}

	@Override
	public RestResponse CurriculumEvaluation(Map<String, Object> paramsMap,RestResponse response)
			throws DataAccessException {
		int i = bizDao.CurriculumEvaluation(paramsMap);
		if(i <= 0){
			response.setErrorcode(1);
			response.setMessage("课程评价失败！");
		}else{
			response.setMessage("课程评价成功！");
			response.setErrorcode(0);
		}
		return response;
	}
	
	@Override
	public RestResponse getCourseEvaluate(Map<String, Object> paramsMap,RestResponse response)
			throws DataAccessException {
		List<Map<String,Object>> resultMap = bizDao.getCourseEvaluate(paramsMap);
		if(resultMap != null && resultMap.size() > 0){
			response.setErrorcode(0);
			response.setData(resultMap);
		}else{
			response.setErrorcode(1);
			response.setMessage("获取课程评价失败！");
		}
		return response;
	}

	@Override
	public List<Map<String, Object>> NoCourseHistory(
			Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.NoCourseHistory(paramsMap);
	}

	@Override
	public List<Map<String, Object>> waitCourseHistory(
			Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.waitCourseHistory(paramsMap);
	}

	@Override
	public List<Map<String, Object>> finishCourseHistory(String stuid)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.finishCourseHistory(stuid);
	}

	@Override
	public Integer queryCourseNo(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.queryCourseNo(paramsMap);
	}

	@Override
	public Integer finishQueryCourseNo(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.finishQueryCourseNo(paramsMap);
	}

	@Override
	public List<Map<String, Object>> detailsClass(int Id, String imgUrl)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.detailsClass(Id, imgUrl);
	}

	@Override
	public List<Map<String, Object>> CancelAppointInfo(
			Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.CancelAppointInfo(paramsMap);
	}

	@Override
	public List<Map<String, Object>> GetTecReleaseCourse(
			Map<String, Object> paramsMap) throws DataAccessException {
		return bizDao.GetTecReleaseCourse(paramsMap);

	}

	@Override
	public List<Map<String, Object>> GetTecRAppointmentInfo(int courseid,
			String imgUrl) throws DataAccessException {
		return bizDao.GetTecRAppointmentInfo(courseid, imgUrl);

	}

	// 照片上传
	@Override
	public int Insertcheckpic(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.Insertcheckpic(paramsMap);
	}

	@Override
	public int updateStudyStat_Query(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.updateStudyStat_Query(paramsMap);
	}

	@Override
	public int updateStudyStat_Student(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.updateStudyStat_Student(paramsMap);
	}

	@Override
	public int updateStudyStatByDay(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.updateStudyStatByDay(paramsMap);
	}

	@Override
	public List<Map<String, Object>> getphotobystuid(
			Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getphotobystuid(paramsMap);
	}

	@Override
	public Map<String, Object> getSubjectParambysubjectid(int subjectid)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getSubjectParambysubjectid(subjectid);
	}

	@Override
	public Map<String, Object> getStudyStat_Querybystuid(int userid)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getStudyStat_Querybystuid(userid);
	}

	@Override
	public Map<String, Object> getSchoolSubjectsbysubid(Map<String, Object> map)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getSchoolSubjectsbysubid(map);
	}

	@Override
	public int InsertStuExamResult(Map<String, Object> map)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.InsertStuExamResult(map);
	}

	@Override
	public RestResponse getStudentLearnVideo(Map<String, Object> paramsMap,RestResponse response)
			throws DataAccessException {
		List<Map<String, Object>> listData = bizDao.getStudentLearnVideo(paramsMap);
		if(null!=listData&&listData.size()>0){
			  // 设置数据集合
			  response.setData(listData);
		}else{
			response.setErrorcode(1);
			response.setMessage("系统无视频记录！");
		}
		return response;
	}
	
	@Override
	public RestResponse getUserLearnVideo(Map<String, Object> paramsMap,RestResponse response)
			throws DataAccessException {
		List<Map<String, Object>> listData = bizDao.getUserLearnVideo(paramsMap);
		if(null!=listData&&listData.size()>0){
			  // 设置数据集合
			  response.setData(listData);
		}else{
			response.setErrorcode(1);
			response.setMessage("系统无视频记录！");
		}
		return response;
	}

	@Override
	public List<Map<String, Object>> getCurVideo(Map<String, Object> paramsMap)
			throws DataAccessException {
		return bizDao.getCurVideo(paramsMap);
	}

	@Override
	public List<Map<String, Object>> getDriverSchoolPhotos(String imgUrl)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getDriverSchoolPhotos(imgUrl);
	}

	@Override
	public RestResponse updateInfo(RestResponse response,Map<String, Object> paramsMap)
			throws DataAccessException {
		//查询手机号是否已经绑定其他账户
		int count = bizDao.selectPhone(paramsMap);
		if(count > 0){
			response.setErrorcode(1);
			response.setMessage("手机号已被其他账户使用！");
		}else{
			// 修改学员账户表中的个人信息
			int i = bizDao.updateStudentAccountByphone(paramsMap);
			if (i <= 0){
				response.setErrorcode(1);
				response.setMessage("学员账号信息修改失败！");
			}
		}
		return response;
	}

	@Override
	public List<Map<String, Object>> getFeedbackListInfo(int stuId)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getFeedbackListInfo(stuId);
	}

	@Override
	public int updateStuGid(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.updateStuGid(paramsMap);
	}


	@Override
	public int addStudyPhoto(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.addStudyPhoto(paramsMap);
	}

	@Override
	public int addVideoPhoto(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.addVideoPhoto(paramsMap);
	}

	@Override
	public RestResponse getVideoInfo(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		String studyStatus = (String) paramsMap.get("studyStatus");
		List<Map<String, Object>> listData = new ArrayList<Map<String, Object>>();
		if (studyStatus.equals("1")) {
			// 获取已学视频
			listData = bizDao.getValidLearnVideo(paramsMap);
			if (null != listData && listData.size() > 0) {
				// 设置数据集合
				response.setData(listData);
			} else {
				response.setErrorcode(1);
				response.setMessage("该学员无已学视频学习信息！");
			}
		} else if (studyStatus.equals("0")) {
			// 获取未学视频
			listData = bizDao.getInvalidLearnVideo(paramsMap);
			if (null != listData && listData.size() > 0) {
				// 设置数据集合
				response.setData(listData);
			} else {
				response.setErrorcode(1);
				response.setMessage("该学员无未学视频学习信息！");
			}
		} else {
			response.setErrorcode(1);
			response.setMessage("视频学习类型无效！");
		}
		return response;
	}

	@Override
	public RestResponse addStudyResult(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		Map<String, Object> teacherMap = bizDao
				.selectTeacherByStudent(paramsMap);
		if (teacherMap != null && !teacherMap.isEmpty()) {
			paramsMap.put("teacherId", teacherMap.get("teacherId"));
			paramsMap.put("teacherName", teacherMap.get("TeacherName"));
			paramsMap.put("coachnum", teacherMap.get("Coachnum"));
		}
		// 从学习结果表中获取最大电子教学日志编号
		String maxRecnum = bizDao.getMaxRecnum();
		NumberFormat f = new DecimalFormat("00000");
		if (null != maxRecnum && !"".equals(maxRecnum)) {
			paramsMap.put("recnum", f.format(Integer.parseInt(maxRecnum) + 1));
		} else {
			paramsMap.put("recnum", "00001");
		}
		// 向tb_StudyRecord_Result表中插入数据
		int i = bizDao.addStudyRecordResult(paramsMap);
		if (i <= 0) {
			response.setErrorcode(1);
			response.setMessage("添加学时失败!");
		}else{
			response.setErrorcode(0);
			response.setData(paramsMap.get("studyResultId"));
		}
		return response;
	}

	@Override
	public RestResponse addVideoRecord(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		// 添加视频学习记录（根据用户进行添加）
		int j = bizDao.addVideoRecord(paramsMap);
		if (j <= 0) {
			response.setErrorcode(1);
			response.setMessage("添加视频学习记录出错!");
		}
		// 查询视频记录数
		int counts = bizDao.selectVideoCount(paramsMap);
		if (counts <= 0) {
			// 添加视频学习记录数
			int k = bizDao.addVideoCount(paramsMap);
			if (k <= 0) {
				response.setErrorcode(1);
				response.setMessage("添加视频学习记录数失败!");
			}
		} else {
			int i = bizDao.updateVideoCount(paramsMap);
			if (i <= 0) {
				response.setErrorcode(1);
				response.setMessage("更改视频学习记录数失败!");
			}
		}
		return response;
	}

	@Override
	public List<Map<String, Object>> getStudentInfoForTerminater(
			Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getStudentInfoForTerminater(paramsMap);
	}

	@Override
	public List<Map<String, Object>> getStudyTimeQueryForTerminater(
			String Stunum, String Subject) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getStudyTimeQueryForTerminater(Stunum, Subject);
	}

	@Override
	public List<Map<String, Object>> getStudyRecordResultForTerminater(
			String Stunum) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getStudyRecordResultForTerminater(Stunum);
	}

	@Override
	public int addOperateLog(Map<String, Object> paramsMap)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.addOperateLog(paramsMap);
	}

	@Override
	public Integer getVehicleIdForFaceCheck(String Devnum)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getVehicleIdForFaceCheck(Devnum);
	}

	@Override
	public Integer getGpsIdForFaceCheck(Integer VehicleId)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getGpsIdForFaceCheck(VehicleId);
	}

	@Override
	public String getUIDForFaceCheck(String Stunum) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.getUIDForFaceCheck(Stunum);
	}

	@Override
	public int isExistUIDForFaceCheck(String UID) throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.isExistUIDForFaceCheck(UID);
	}

	@Override
	public int updateUIDForFaceCheck(String UID, String Stunum)
			throws DataAccessException {
		// TODO Auto-generated method stub
		return bizDao.updateUIDForFaceCheck(UID, Stunum);
	}

	@Override
	public List<Map<String, Object>> getCourseDetailByStatus(
			Map<String, Object> paramsMap) throws DataAccessException {
		return bizDao.getCourseDetailByStatus(paramsMap);
	}

	@Override
	public RestResponse getClassInfoByDriverId(Map<String, Object> hashMap,
			RestResponse response) throws DataAccessException {
		List<Map<String, Object>> listmap = bizDao
				.getClassInfoByDriverId(hashMap);
		if (listmap != null && listmap.size() > 0) {
			response.setErrorcode(0);
			response.setData(listmap);
		} else {
			response.setErrorcode(0);
			response.setMessage("该驾校没有对应的班型信息...");
		}
		return response;
	}

	@Override
	public RestResponse userRegister(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		// 查询该账号有没有已经注册
		String userName = paramsMap.get("username").toString();
		int i = bizDao.getRegisterCount(userName);
		if (i <= 0) {
			// 插入数据到账号表中
			int result = bizDao.UserRegisterInfo(paramsMap);
			if (result <= 0) {
				response.setErrorcode(1);
				response.setMessage("注册失败");
			} else {
				response.setErrorcode(0);
				response.setData(paramsMap);
			}
		} else {
			response.setErrorcode(1);
			response.setMessage("该账号已被注册");
		}
		return response;
	}

	@Override
	public RestResponse updatePassword(String mobilePhone, String oldPwd,
			String newPwd, RestResponse response) throws Exception {
		// 得到学员旧密码
		String databasePwd = bizDao.getStudentOldPwdByTel(mobilePhone);
		// 验证旧密码
		if (!Common.genMDInfo(oldPwd).equals(databasePwd)) {
			// 旧密码验证错误
			response.setErrorcode(1);
			response.setMessage("旧密码填写错误！");
		} else {
			// 修改密码
			int i = bizDao.updateStuPwd(Common.genMDInfo(newPwd), mobilePhone);
			if (i == 0) {
				response.setErrorcode(1);
				response.setMessage("密码修改失败！");
			} else {
				response.setErrorcode(0);
				response.setMessage("密码修改成功！");
			}
		}
		return response;
	}

	@Override
	public RestResponse updateUserPhoto(String userId, String image64Base,
			RestResponse response) throws Exception {
		LocalDateTime now = LocalDateTime.now();
		String year = String.valueOf(now.getYear());// 年
		String month = String.valueOf(now.getMonthValue());// 月
		String day = String.valueOf(now.getDayOfMonth());// 日
		String fileName = year.trim() + month.trim() + day.trim()
				+ UUID.randomUUID().toString() + "-blob-student.jpg";
		/*String path = Config.getImageSave() + "/Upload/images/student/"
				+ fileName;

		BASE64Decoder decoder = new BASE64Decoder();
		//Base64解码  
        byte[] b = decoder.decodeBuffer(image64Base);  
        for(int i=0;i<b.length;++i)  
        {  
            if(b[i]<0)  
            {//调整异常数据  
                b[i]+=256;  
            }  
        }  
		// 添加新的图片到目录中
		File currfile = new File(path);
		if (currfile.getParent() != null
				&& !new File(currfile.getParent()).exists()) {
			new File(currfile.getParent()).mkdirs();// （文件前面的路径不存在，则创建该路径）
		}
		if (!currfile.exists()) {
			currfile.createNewFile();// 如果不存在该文件，则创建
		}
		FileOutputStream fos = new FileOutputStream(path);
		fos.write(b);
		fos.flush();
		fos.close();
		// 删除旧的图片
		String oldStudentPhoto = bizDao.GetStudentPhoto(userId);
		File f = new File(Config.getImageSave()
				+ oldStudentPhoto.replace("/", "\\"));
		f.delete();*/
		String imageUrl = Config.getImageURL();
		String url = imageUrl + "/api/services/app/StudentBase/AddStudentPicbase64";
		Map<String,Object> a = new HashMap<String,Object>();
		a.put("file", image64Base);
		a.put("fileName", fileName);
		JSONObject jsonObj = new JSONObject(a);//转化为json格式  
		BaseService.HttpPostWithJson(url,jsonObj.toJSONString());
		// 修改学员头像地址
		String studentPhoto = "/Upload/images/student/" + fileName;
		int i = bizDao.UpdatePhoto(studentPhoto, userId);
		if (i > 0) {
			response.setErrorcode(0);
			response.setMessage("用户头像修改成功！");
		} else {
			response.setErrorcode(1);
			response.setMessage("用户头像修改失败！");
		}
		return response;
	}

	@Override
	public int updateStuPwd(String pwd, String mobilePhone)
			throws DataAccessException {
		return bizDao.updateStuPwd(pwd, mobilePhone);
	}

	@Override
	public RestResponse BIndOrNot(Map<String, Object> paramsMap,
			RestResponse response) throws Exception {
		// 根据身份证号获取学员ID
		List<Map<String, Object>> stumap = bizDao.getStudentID(paramsMap);
		if (null != stumap && stumap.size() > 0) {
			String student = stumap.get(0).get("studentId").toString();
			int uploadStatus = (int) stumap.get(0).get("UploadStatus");
			int status = (int) stumap.get(0).get("Status");
			String bindtype = paramsMap.get("bindtype").toString();
			if (bindtype.equals("1")) {
				//查看该学员是否激活或备案
				if ((uploadStatus == 2 || uploadStatus == 3) && (status == 1)) {
					// 判断该学员是否已经绑定过
					int isBindCount = bizDao.getIsBind(Integer.parseInt(student));
					if (isBindCount > 0) {
						response.setErrorcode(1);
						response.setMessage("您的学员信息已绑定其他账号，请先在原账号解绑后再行绑定！");
					} else {
						paramsMap.put("studentid", student);
						int result = bizDao.BindUserInfo(paramsMap);
						if (result <= 0) {
							response.setErrorcode(1);
							response.setMessage("操作失败");
						} else {
							response.setErrorcode(0);
							response.setMessage("绑定成功");
						}
					}
				} else {
					if(!(uploadStatus == 2 || uploadStatus == 3)){
						response.setErrorcode(1);
						response.setMessage("该学员未备案！");
					}else if(status != 1){
						response.setErrorcode(1);
						response.setMessage("该学员未激活！");
					}
				}
			} else if (bindtype.equals("0")) {
				paramsMap.put("studentid", 0);
				paramsMap.put("idcardno", "");
				int result = bizDao.BindUserInfo(paramsMap);
				if (result <= 0) {
					response.setErrorcode(1);
					response.setMessage("操作失败");
				} else {
					response.setErrorcode(0);
					response.setMessage("解绑成功");
				}
			}
		} else {
			response.setErrorcode(1);
			response.setMessage("该用户没有线下报名");
		}
		return response;
	}
	
	@Override
	public RestResponse activeStudent(Map<String, Object> paramsMap,
			RestResponse response) throws Exception {
		// 根据身份证号获取学员ID
		List<Map<String, Object>> stumap = bizDao.getStudentID(paramsMap);
		if (null != stumap && stumap.size() > 0) {
			String studentId = stumap.get(0).get("studentId").toString();
			String driveSchoolId = Optional.ofNullable(stumap.get(0).get("DriveSchoolId")).orElse("").toString();
			paramsMap.put("studentId", studentId);
			paramsMap.put("driveSchoolId", driveSchoolId);
			int status = (int) stumap.get(0).get("Status");
			if (status != 1) {
				//判断激活码是否已被使用
				Map<String, Object> codeMap = bizDao.getCodeIsUse(paramsMap);
				//String registrationNumber = Optional.ofNullable(codeMap.get("RegistrationNumber")).orElse("").toString();
				if(null != codeMap && codeMap.size() > 0){
					String useState = Optional.ofNullable(codeMap.get("UseState")).orElse("").toString();
					if(useState.equals("1")){
						response.setErrorcode(1);
						response.setMessage("该激活码已被使用");
					}else{
						//激活
						int i = bizDao.updateCodeStatus(paramsMap);
						if(i > 0){
							int j = bizDao.updateStuStatus(paramsMap);
							if(j > 0){
								response.setErrorcode(0);
							    response.setMessage("激活成功");
							}else{
								response.setErrorcode(1);
							    response.setMessage("激活失败");
							}	
						}else{
							
						}
					}
				}else{
				    response.setErrorcode(1);
				    response.setMessage("激活码输入错误");
			   }	
			} else {
				response.setErrorcode(1);
				response.setMessage("该学员已激活");
			}
		} else {
			response.setErrorcode(1);
			response.setMessage("该用户没有线下报名");
		}
		return response;
	}

	@Override
	public RestResponse getDriverSchoolDtail(String driverId, String driveType,
			String imgUrl, RestResponse response) throws DataAccessException {
		List<Map<String, Object>> map = new ArrayList<Map<String, Object>>();
		if (driveType.equals("1")) {
			map = bizDao.getDriveSchoolDetailInfo(Integer.parseInt(driverId),
					imgUrl);
		} else if (driveType.equals("2")) {
			map = bizDao.getBranchDriveSchoolDetailInfo(
					Integer.parseInt(driverId), imgUrl);
		}
		if (map != null && map.size() > 0) {
			// 设置Json集合
			for (Map<String, Object> maps : map) {
				Map<String, Object> hashMap = new HashMap<String, Object>();
				hashMap.put("driverId", maps.get("driverId").toString());
				hashMap.put("driveType", driveType);
				maps.put("classinfo", bizDao.getClassInfoByDriverId(hashMap));
			}
			response.setData(map);
		} else {
			response.setErrorcode(1);
			response.setMessage("系统无该驾校的详情信息...");
		}
		return response;
	}

	@Override
	public Map<String, Object> getDriverByTeacher(String teacherId)
			throws DataAccessException {
		return bizDao.getDriverByTeacher(teacherId);
	}

	@Override
	public RestResponse courseAppoint(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException, ParseException {
		//查询该学员是否是黑名单学员(黑名单学员提示不可预约)
		int blackCount = bizDao.getBlackRecord(paramsMap);
		if(blackCount > 0){
			response.setErrorcode(1);
			response.setMessage("无法预约课程，请联系管理员！");
		}else{
			// 查询该课程的详细信息
			Map<String, Object> appointMap = bizDao.FindappointmentCount(paramsMap);
			if (appointMap != null && !appointMap.isEmpty()) {
				// 获取课程的所属科目
				String subjectId = appointMap.get("courseType").toString();
				// 课程可约学员数
				int appointcount = Integer.parseInt(appointMap
						.get("appointmentCount").toString().isEmpty() ? "0"
						: appointMap.get("appointmentCount").toString());
				// 课程已约学员数
				int hasAppointcount = Integer.parseInt(appointMap
						.get("hasAppointmentCount").toString().isEmpty() ? "0"
						: appointMap.get("hasAppointmentCount").toString());
				// 获取课程日期
				String courseDate = appointMap.get("courseDate").toString();
				// 获取课程时间段
				String courseTimeSlot = appointMap.get("courseTimeSlot").toString();
				String courseNo = Optional.ofNullable(appointMap.get("courseNo")).orElse("").toString();
				String coursePrice = appointMap.get("coursePrice").toString();
				String courseDiscount = appointMap.get("courseDiscount").toString();
				paramsMap.put("courseDate", courseDate);
				paramsMap.put("courseTimeSlot", courseTimeSlot);
				String courseStartTime = appointMap.get("courseStartTime").toString();
				SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 
				Date startTime = sdf.parse(courseStartTime); 
				Date nowTime = new Date();
				if(startTime.before(nowTime)){
					response.setErrorcode(1);
					response.setMessage("当前时间大于课程开始时间，无法预约！");
					return response;
				}
				// 从已预约记录中查询是否有和当前要预约课程时间段一致的课程
				int count = bizDao.findAppointmentByTime(paramsMap);
				// 时间一致，则提示不能预约同一时间段的课程
				if (count <= 0) {
					// 课程预约人数已满，则不能预约
					if (hasAppointcount < appointcount) {
						
						// 判断该课程的支付方式，2余额支付的扣学时，1无需支付的不扣学时
						if (appointMap.get("payPath").toString().equals("2")) {
							// 获取学员可约学时
							Map<String, Object> studytime = bizDao
									.SelectSumSurplusStudyTimes(paramsMap);
							if (studytime != null) {
								// 需要加的学时
								Double times = 0.0;
								// 科一剩余学时
								Double Part1SUMHours = Double.parseDouble(studytime
										.get("Part1SUMHours").toString());
								// 科二剩余学时
								Double Part2SUMHours = Double.parseDouble(studytime
										.get("Part2SUMHours").toString());
								// 科三剩余学时
								Double Part3SUMHours = Double.parseDouble(studytime
										.get("Part3SUMHours").toString());
								// 科四剩余学时
								Double Part4SUMHours = Double.parseDouble(studytime
										.get("Part4SUMHours").toString());
								// 计算课程时长
								Double longTime = Double.parseDouble(appointMap
										.get("intervalTime").toString());
								// 需要加的学时数
								if (appointcount != 0) {
									times = Math.floor(longTime / appointcount);
								}

								if (subjectId.equals("12")) {
									if (Part1SUMHours - times < 0) {
										response.setErrorcode(1);
										response.setMessage("科目一剩余学时不足，无法预约！");
										return response;
									}
								}
								if (subjectId.equals("22")) {
									if (Part2SUMHours - times < 0) {
										response.setErrorcode(1);
										response.setMessage("科目二剩余学时不足，无法预约！");
										return response;
									}
								}
								if (subjectId.equals("32")) {
									if (Part3SUMHours - times < 0) {
										response.setErrorcode(1);
										response.setMessage("科目三剩余学时不足，无法预约！");
										return response;
									}
								}
								if (subjectId.equals("42")) {
									if (Part4SUMHours - times < 0) {
										response.setErrorcode(1);
										response.setMessage("科目四剩余学时不足，无法预约！");
										return response;
									}
								}
								paramsMap.put("courseType", subjectId);
								paramsMap.put("count", times);
								// 更新tb_SurplusStudyTime，剩余学时表
								bizDao.updateSurplusStudyTimes(paramsMap);
							}
						}
						
						// 查询是否存在该课程的预约记录
						int num = bizDao.isExisitAppointment(paramsMap);
						if (num > 0) {
							// 如果存在，修改预约记录为已预约（针对取消的情况）
							bizDao.updateCourseAppointment(paramsMap);
						} else {
							// 增加预约记录
							paramsMap.put("courseType", subjectId);
							paramsMap.put("courseNo", courseNo);
							paramsMap.put("coursePrice", coursePrice);
							paramsMap.put("courseDiscount", courseDiscount);
							bizDao.CourseAppointment(paramsMap);
						}
						// 给课程表的已预约人数+1
						bizDao.AddReleaseCourseCount(Integer.parseInt(paramsMap
								.get("CourseID").toString()));

						response.setMessage("预约成功！");
					} else {
						response.setErrorcode(1);
						response.setMessage("该课程的预约学员数已满！");
					}
				} else {
					response.setErrorcode(1);
					response.setMessage("不能再次预约同一时间段的课程！");
				}
			} else {
				response.setErrorcode(1);
				response.setMessage("系统没有查询到该课程！");
			}
			
		}
		return response;
	}

	@Override
	public RestResponse deleteAppoint(Map<String, Object> paramsMap,
			RestResponse response) throws DataAccessException {
		// 要取消的学时
		Double times = 0.0;
		// 查询该课程的相关信息
		Map<String, Object> appointMap = bizDao.FindappointmentCount(paramsMap);
		if (appointMap != null && !appointMap.isEmpty()) {
			DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
			String courseStartTime = appointMap.get("courseStartTime").toString();
			if(courseStartTime.substring(0, courseStartTime.indexOf(":")).length() < 13){
				courseStartTime = courseStartTime.substring(0, courseStartTime.indexOf(" ")+1)+ "0"  
						+ courseStartTime.substring(courseStartTime.indexOf(" ")+1, courseStartTime.indexOf(" ")+5) + ":00";  
			}
			LocalDateTime localDateTime = LocalDateTime.now();
			LocalDateTime courseTime = LocalDateTime.parse(courseStartTime,df);
			long minutes = Duration.between(localDateTime,courseTime ).toMinutes();
			if(minutes <= 12*60){
				response.setErrorcode(1);
				response.setMessage("不能取消12小时之内的课程！");
				return response;
			}else{
				// 课程可预约人数
				int appointcount = Integer.parseInt(appointMap.get(
						"appointmentCount").toString());
				// 计算课程时长
				Double longTime = Double.parseDouble(appointMap.get("intervalTime")
						.toString());
				if (appointcount != 0) {
					times = Math.floor(longTime / appointcount);
				}
				// 更改预约状态为已取消
				int i = bizDao.deleteCourseAppointment(paramsMap);
				paramsMap.put("subjectid", appointMap.get("courseType").toString());
				if (i > 0) {
					// 给课程表的已预约人数-1
					bizDao.DelReleaseCourseCount(Integer.parseInt(paramsMap.get(
							"CourseID").toString()));
					paramsMap.put("count", times);
					// 判断该课程的支付方式，2余额支付的扣学时，1无需支付的不扣学时
					if (appointMap.get("payPath").toString().equals("2")) {
						// 更新tb_SurplusStudyTime
						bizDao.DelupdateSurplusStudyTimes(paramsMap);
					}
					response.setErrorcode(0);
					response.setMessage("取消预约成功！");
				} else {
					response.setErrorcode(1);
					response.setMessage("取消预约失败！");
				}
			}
		} else {
			response.setErrorcode(1);
			response.setMessage("系统没有查询到该课程！");
		}
		return response;
	}

	@Override
	public RestResponse selectPageDatas(Map<String, Object> valMap,
			String studentId, String subjectId, RestResponse response)
			throws DataAccessException {
		Map<String, Object> totalMap = bizDao.getTotalTimes(valMap.get("driverType").toString());
		Map<String, Object> studyMap = bizDao.getStudyTimes(studentId);
		String totalTimes = "0";
		String studyTimes = "0";
		if (totalMap != null && totalMap.size() > 0) {
			if (subjectId.equals("1")) {
				totalTimes = totalMap.get("Subject1ToTalAmt").toString();
			} else if (subjectId.equals("2")) {
				totalTimes = totalMap.get("Subject2ToTalAmt").toString();
			} else if (subjectId.equals("3")) {
				totalTimes = totalMap.get("Subject3ToTalAmt").toString();
			} else if (subjectId.equals("4")) {
				totalTimes = totalMap.get("Subject4ToTalAmt").toString();
			}
		}
		if (studyMap != null && studyMap.size() > 0) {
			if (subjectId.equals("1")) {
				studyTimes = studyMap.get("Part1Hours").toString();
			} else if (subjectId.equals("2")) {
				studyTimes = studyMap.get("Part2Hours").toString();
			} else if (subjectId.equals("3")) {
				studyTimes = studyMap.get("Part3Hours").toString();
			} else if (subjectId.equals("4")) {
				studyTimes = studyMap.get("Part4Hours").toString();
			}
		}
       //一下统计视频学习信息暂时不需要，在本地获取顺序练习的学习进度
		/*Map<String, Object> totalOnlineVedioMap = bizDao
				.getTotalOnlineVedio(subjectId);
		Map<String, Object> studyOnlineVedioMap = bizDao
				.getStudyOnlineVedio(valMap);
		String totalOnlineVedio = "0";
		String studyOnlineVedio = "0";
		if (totalOnlineVedioMap != null && totalOnlineVedioMap.size() > 0) {
			totalOnlineVedio = totalOnlineVedioMap.get("num").toString();
		}
		if (studyOnlineVedioMap != null && studyOnlineVedioMap.size() > 0) {
			studyOnlineVedio = studyOnlineVedioMap.get("num").toString();
		}*/
		String simulateScore = "0";
		Map<String, Object> simulateScoreMap = bizDao.getSimulateScore(valMap);
		if (simulateScoreMap != null && simulateScoreMap.size() > 0) {
			simulateScore = simulateScoreMap.get("Score").toString();
		}
		Map<String, Object> stumap = new HashMap<String, Object>();
		stumap.put("totalTimes", totalTimes);
		stumap.put("studyTimes", studyTimes);
		stumap.put("simulateScore", simulateScore);
		response.setErrorcode(0);
		response.setData(stumap);
		return response;
	}

	@Override
	public RestResponse selectQuestion(Map<String, Object> valMap,
			RestResponse response) throws DataAccessException {
		String studyType = valMap.get("studyType").toString();
		List<Map<String, Object>> map = new ArrayList<Map<String, Object>>();
		if (studyType.equals("1")) {
			checkParamsMapForPage(valMap);
			// 顺序练习（根据科目、学驾类型获取 所有试题）
			map = bizDao.getAllQuestionInfo(valMap);
		}
		if (studyType.equals("2")) {
			// 章节练习--根据章节类型、科目、学驾类型获取
			map = bizDao.getParmQuestionInfo(valMap);
		}
		if (studyType.equals("3")) {
			checkParamsMapForPage(valMap);
			// 随机练习（根据科目、学驾类型获取 所有试题）
			map = bizDao.getRandomQuestionInfo(valMap);
		}
		if (map != null && map.size() > 0) {
			for (Map<String, Object> maps : map) {
				maps.put("questionitems",bizDao.getQuestionItemInfo(maps.get("QuestionId").toString()));
				maps.put("sign","");
			}
			response.setData(map);
		} else {
			response.setErrorcode(1);
			response.setMessage("该练习类型下无题目信息...");
		}
		return response;
	}

	@Override
	public RestResponse addPreRegister(Map<String, Object> valMap,
			RestResponse response) throws DataAccessException {
		// 查询该人填的号码是否与注册的号码一致(所有验证功能暂时去掉，后来有再加上的可能)
		//Map<String, Object> acountMap = bizDao.selectAcountByPhone(valMap.get("mobilephone").toString());
		//if (acountMap != null && acountMap.size() > 0) {
			// 检查用户是否已绑定(已绑定用户不可提交报名意向)
			//int acount = bizDao.checkIsBind(Integer.parseInt(acountMap.get("StudentId").toString()));
			//if (acount <= 0) {
				// 新增报名意向
				int i = bizDao.AddPreRegistration(valMap);
				if (i <= 0) {
					response.setErrorcode(1);
					response.setMessage("新增报名意向失败...");
				}
			//} else {
				//response.setErrorcode(1);
				//response.setMessage("该用户已绑定，不能提交报名意向...");
			//}
		//} else {
			//response.setErrorcode(1);
			//response.setMessage("不是本人手机号不可提交...");
		//}
		return response;
	}

	@Override
	public int updateUserInfo(int userId) throws DataAccessException {
		int i = bizDao.updateUserInfo(userId);
		int j = i / 0;
		return j;
	}
	@Override
	public int InsertInfo(Map<String, Object> map) throws DataAccessException {
		int i = bizDao.InsertInfo(map);	
		return i;
	}

	@Override
	public RestResponse addStudyPhoto(Map<String, Object> valMap,
			RestResponse response) throws Exception {
		String image64Base = (String) valMap.get("image64Base");
		LocalDateTime now = LocalDateTime.now();
		String year = String.valueOf(now.getYear());// 年
		String month = String.valueOf(now.getMonthValue());// 月
		String day = String.valueOf(now.getDayOfMonth());// 日
		String fileName = year.trim() + month.trim() + day.trim()
				+ UUID.randomUUID().toString() + ".jpg";
		String photoPath = "/imagepath/onlinephoto/" + year.trim() + "/"
				+ month.trim() + "/" + day.trim() + "/" + fileName;
		String path = Config.getImageSave() + photoPath;
		
		BASE64Decoder decoder = new BASE64Decoder();
		//Base64解码  
        byte[] b = decoder.decodeBuffer(image64Base);  
        for(int i=0;i<b.length;++i)  
        {  
            if(b[i]<0)  
            {//调整异常数据  
                b[i]+=256;  
            }  
        }  
		// 添加新的图片到目录中
		File currfile = new File(path);
		if (currfile.getParent() != null
				&& !new File(currfile.getParent()).exists()) {
			new File(currfile.getParent()).mkdirs();// （文件前面的路径不存在，则创建该路径）
		}
		if (!currfile.exists()) {
			currfile.createNewFile();// 如果不存在该文件，则创建
		}
		FileOutputStream fos = new FileOutputStream(path);
		fos.write(b);
		fos.flush();
		fos.close();
		// 添加图片地址到记录表中
		valMap.put("photoPath", photoPath);
		int i = bizDao.addStudyPhoto(valMap);
		if (i > 0) {
			response.setErrorcode(0);
			response.setMessage("添加学习照片成功！");
		} else {
			response.setErrorcode(1);
			response.setMessage("添加学习照片失败！");
		}
		return response;
	}

	@Override
	public RestResponse addStudentEvaluate(Map<String, Object> valMap,
			RestResponse response) throws Exception {
		int i = bizDao.addStudentEvaluate(valMap);
		if (i > 0) {
			response.setErrorcode(0);
			response.setMessage("添加评价成功！");
		} else {
			response.setErrorcode(1);
			response.setMessage("添加评价失败！");
		}
		return response;
	}

	@Override
	public RestResponse addVideoEvaluate(Map<String, Object> valMap,
			RestResponse response) throws Exception {
		int i = bizDao.addVideoEvaluate(valMap);
		if (i > 0) {
			response.setErrorcode(0);
			response.setMessage("添加评价成功！");
		} else {
			response.setErrorcode(1);
			response.setMessage("添加评价失败！");
		}
		return response;
	}

	@Override
	public RestResponse getStudentEvaluate(Map<String,Object> valMap,
			RestResponse response) throws Exception {
		List<Map<String, Object>> evaluateMap = bizDao.getStudentEvaluate(valMap);
		if(evaluateMap != null && evaluateMap.size() >0 ){
			response.setErrorcode(0);
			response.setData(evaluateMap);
		}else{
			response.setErrorcode(1);
			response.setMessage("系统无数据！");
		}
		return response;
	}

	@Override
	public RestResponse getVideoEvaluate(String videoId,String imgUrl,
			RestResponse response) throws Exception {
		List<Map<String, Object>> evaluateMap = bizDao.getVideoEvaluate(videoId,imgUrl);
		if(evaluateMap != null && evaluateMap.size() >0 ){
			response.setErrorcode(0);
			response.setData(evaluateMap);
		}else{
			response.setErrorcode(1);
			response.setMessage("系统无数据！");
		}
		return response;
	}
	
	@Override
	public RestResponse checkStudentEvaluateOne(Map<String,Object> valMap,
			RestResponse response) throws Exception {
		int count = bizDao.checkStudentEvaluateOne(valMap);
		if(count > 0 ){
			response.setErrorcode(1);
			response.setMessage("已评价，不可操作！");
		}else{
			response.setErrorcode(0);
			response.setMessage("可评价！");
		}
		return response;
	}
	@Override
	public RestResponse checkVideoEvaluateOne(Map<String,Object> valMap,
			RestResponse response) throws Exception {
		int count = bizDao.checkVideoEvaluateOne(valMap);
		if(count > 0 ){
			response.setErrorcode(1);
			response.setMessage("已评价，不可操作！");
		}else{
			response.setErrorcode(0);
			response.setMessage("可评价！");
		}
		return response;
	}
	@Override
	public RestResponse checkCourseEvaluateOne(Map<String,Object> valMap,
			RestResponse response) throws Exception {
		//查询课程是否已评价
		int count = bizDao.checkCourseEvaluateOne(valMap);
		if(count > 0 ){
			response.setErrorcode(1);
			response.setMessage("已评价，不可操作！");
		}else{
			//查询课程是否已完成（课程结束时间在当前时间以前，且未缺勤）
			String endDate = bizDao.getCourseEndDate(valMap); 
			if(endDate != null){
				DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
				LocalDateTime endtime = LocalDateTime.parse(endDate.substring(0,19), df);
				if(!endtime.isBefore(LocalDateTime.now())){
					response.setErrorcode(1);
					response.setMessage("该课程未完成学习，不可评价！");
				}else{
					String isAbsence = bizDao.isAbsence(valMap);
					if(Optional.ofNullable(isAbsence).orElse("").equals("1")){
						response.setErrorcode(1);
						response.setMessage("学员该课程缺勤，不可评价！");
					}else{
						response.setErrorcode(0);
						response.setMessage("可评价！");
					}
				}
			}else{
				response.setErrorcode(1);
				response.setMessage("数据异常，不可评价！");
			}
		}
		return response;
	}

	@Override
	public RestResponse getVideoRecordList(String userId, RestResponse response)
			throws Exception {
		List<Map<String, Object>> videoMap = bizDao.getVideoRecordList(userId);
		if(videoMap != null && videoMap.size() >0 ){
			response.setErrorcode(0);
			response.setData(videoMap);
		}else{
			response.setErrorcode(1);
			response.setMessage("系统无数据！");
		}
		return response;
	}

	@Override
	public RestResponse getExamRecordList(String userId, RestResponse response)
			throws Exception {
		List<Map<String, Object>> examMap = bizDao.getExamRecordList(userId);
		if(examMap != null && examMap.size() >0 ){
			response.setErrorcode(0);
			response.setData(examMap);
		}else{
			response.setErrorcode(1);
			response.setMessage("系统无数据！");
		}
		return response;
	}
	

	@Override
	public RestResponse writeAbnormalLog(List<Map<String, Object>> listMap,
			RestResponse response) throws DataAccessException {
		int i = bizDao.writeAbnormalLog(listMap);
		if(i > 0){
			response.setErrorcode(0);
			response.setMessage("插入记录成功");
		}else{
			response.setErrorcode(1);
			response.setMessage("插入记录失败");
		}
		return response;
	}

	@Override
	public Map<String, Object> getDevnumByPhone(String factoryNo) throws DataAccessException {
		return bizDao.getDevnumByPhone(factoryNo);
	}

}
